DAY12:Complementary DNA


Posted by birdbirdmurmur on 2023-07-25

題目連結:

Complementary DNA

解法:

function DNAStrand(dna){
  return dna.replace(/[ACTG]/g, match =>{
    switch(match){
      case "A":
        return "T";
      case "T":
        return "A";
      case "C":
        return "G";
      case "G":
        return "C";
    }
  })
}

筆記:

替換字先想到replace()
/[ATCG]/g:找到所有A、T、C、G四個字母
switch()將傳遞進來的值通過case轉換成另外一個字


#javascript #Codewars #replace #switch







Related Posts

不要動!把表單交出來(1) - formData

不要動!把表單交出來(1) - formData

[Python] 好用的 concurrent.futures is a good way to speed up your function

[Python] 好用的 concurrent.futures is a good way to speed up your function

 # Python 爬取與存取空氣品質 PM2.5 AQI

# Python 爬取與存取空氣品質 PM2.5 AQI


Comments